package com.taiyi.renaissancemall.ui.mine.order.evaluation;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.FindExpressBean;
import com.taiyi.renaissancemall.bean.OrderDetailBean;
import com.taiyi.renaissancemall.bean.RefundResultBean;
import com.taiyi.renaissancemall.bean.VerifiedBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;
import com.taiyi.renaissancemall.ui.mine.order.sale.refund.ApplyRefundView;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Response;

public class EvaluationPresent extends BasePresent<EvaluationView> {

    public void getOrderDetail(String ordercommodityid) {
        Map<String, String> map = new HashMap<>();
        map.put("ordercommodityid", ordercommodityid);
        HttpUtils.postRequest(BaseUrl.GET_ORDER_DETAIL, this, map, new JsonCallback<BaseResultBean<OrderDetailBean>>() {
            @Override
            public BaseResultBean<OrderDetailBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<OrderDetailBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.getOrderDetailSuccess(response.body().data);
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {
                    view.getOrderDetailFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<OrderDetailBean>> response) {
                super.onError(response);
            }
        });
    }

    //提交评价
    public void toCommitEvaluation(String ordercommodityid, String commodityscore, String evimgurl, String evaluate_ramrk) {
        Map<String, String> map = new HashMap<>();
        map.put("ordercommodityid", ordercommodityid);
        map.put("commodityscore", commodityscore);
        map.put("evimgurl", evimgurl);
        map.put("evaluate_ramrk", evaluate_ramrk);
        HttpUtils.postRequest(BaseUrl.ADD_COMMENT, this, map, new JsonCallback<BaseResultBean<VerifiedBean>>() {
            @Override
            public BaseResultBean<VerifiedBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<VerifiedBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.toEvaluationSuccess(response.body().msg_cn);
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {
                    view.toEvaluationFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<VerifiedBean>> response) {
                super.onError(response);
            }
        });
    }

}
